<?php

namespace Liuhelong\LaravelAdmin\Wechat\Actions\WechatOffiaccountBroadcast;

use Encore\Admin\Actions\RowAction;
use Illuminate\Http\Request;
use Illuminate\Database\Eloquent\Model;

class Del extends RowAction
{
    public $name = '删除群发';
    private $wechat;
    
    public function __construct(){
        $this->wechat = app('liuhelong_wechat_service');
        parent::__construct();
    }
    
    public function form()
    {
		$this->text('article_idx', '删除图文第几条')->help('要删除的文章在图文消息中的位置，第一篇编号为1，该字段不填或填0会删除全部文章');
    }
	
	public function handle(Model $model, Request $request)
    {
		try{
		    $this->wechat->handle('broadcasting','delete',[$model->msg_id,(int)$request->article_idx]);
					
			return $this->response()->success('删除成功！')->refresh();
		}catch(\Exception $e){
			return $this->response()->error($e->getMessage())->refresh();
		}
    }
    
}